package com.slot.faraohgoldview;

public class CheckWin {
	public int scatter = 0;
	public int win=0;
	public int[] winSimbols;
	public int[] winPerSymbols;
	public int winLines=0;
	private int winSimbol;
	private int winPerSymbol;
	
	static final int[][] LINE = { { 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2 },
			{ 0, 0, 0, 0, 0 }, { 2, 1, 0, 1, 2 }, { 0, 1, 2, 1, 0 },
			{ 1, 0, 0, 0, 1 }, { 1, 2, 2, 2, 1 }, { 2, 2, 1, 0, 0 },
			{ 0, 0, 1, 2, 2 }, };

	public void checkLines(int[][] symbols, int lines) {
		int i;
		winSimbols = new int[lines];
		winPerSymbols = new int[lines];
		int[][] symbolLine = new int[lines][FaraohGoldView.REELS];
		for (int r = 0; r < FaraohGoldView.REELS; r++) {
			for (i = 0; i < 3; i++) {
				if (symbols[r][i] == 12){
					scatter++;
				}
			}
			for(i=0;i<lines;i++){
				symbolLine[i][r]=symbols[r][LINE[i][r]];
			}
		}
		for (i = 0; i < lines; i++) {
			checkPerLine(symbolLine[i]);
			winSimbols[i] = winSimbol;
			winPerSymbols[i]=winPerSymbol;
			if(winSimbols[i]>0){
				winLines++;
				win+=winPerSymbol;
			}
		}
		if(scatter>1){
			winLines++;
		}
	}

	private void checkPerLine(int[] line) {
		winSimbol=0;
		winPerSymbol=0;
		int nine= 0;
		int ten = 0;
		int jack = 0;
		int ace = 0;
		int queen = 0;
		int king = 0;
		int bird = 0;
		int sphinx = 0;
		int tablet = 0;
		int bug = 0;
		int cat = 0;
		int pharaoh = 0;
		for (int r = 0; r < FaraohGoldView.REELS; r++) {
			if (line[r] == 0) {
				if (pharaoh == r) {
					pharaoh++;
					cat++;
					bug++;
					tablet++;
					sphinx++;
					bird++;
					ace++;
					king++;
					queen++;
					jack++;
					ten++;
					nine++;
				} else if (cat == r) {
					cat++;
				} else if (bug == r) {
					bug++;
				} else if (tablet == r) {
					tablet++;
				} else if (sphinx == r) {
					sphinx++;
				} else if (bird == r) {
					bird++;
				} else if (ace == r) {
					ace++;
				} else if (king == r) {
					king++;
				} else if (queen == r) {
					queen++;
				} else if (jack == r) {
					jack++;
				} else if (ten == r) {
					ten++;
				} else if (nine == r) {
					nine++;
				}
			} else if (line[r] == 1 && sphinx == r) {
				sphinx++;
			} else if (line[r] == 2 && tablet == r) {
				tablet++;
			} else if (line[r] == 3 && bird == r) {
				bird++;
			} else if (line[r] == 4 && cat == r) {
				cat++;
			} else if (line[r] == 5 && bug == r) {
				bug++;
			} else if (line[r] == 6 && ace == r) {
				ace++;
			} else if (line[r] == 7 && king == r) {
				king++;
			} else if (line[r] == 8 && queen == r) {
				queen++;
			} else if (line[r] == 9 && jack == r) {
				jack++;
			} else if (line[r] == 10 && ten == r) {
				ten++;
			} else if (line[r] == 11 && nine == r) {
				nine++;
			}
		}
		if (pharaoh == 2) {
			if (nine > 2) {
				winSimbol = nine;
				winPerSymbol=FaraohGoldView.NINE_TABLE[nine]*2;
			} else if (ten > 2) {
				winSimbol = ten;
				winPerSymbol=FaraohGoldView.TENJACKQUEEN_TABLE[ten]*2;
			} else if (jack > 2) {
				winSimbol = jack;
				winPerSymbol=FaraohGoldView.TENJACKQUEEN_TABLE[jack]*2;
			} else if (queen > 2) {
				winSimbol = queen;
				winPerSymbol=FaraohGoldView.TENJACKQUEEN_TABLE[queen]*2;
			} else if (king > 2) {
				winSimbol = king;
				winPerSymbol=FaraohGoldView.KINGACE_TABLE[king]*2;
			} else if (ace > 2) {
				winSimbol = ace;
				winPerSymbol=FaraohGoldView.KINGACE_TABLE[ace]*2;
			} else if (bug > 2) {
				winSimbol = bug;
				winPerSymbol=FaraohGoldView.BUGCAT_TABLE[bug]*2;
			} else if (cat > 2) {
				winSimbol = cat;
				winPerSymbol=FaraohGoldView.BUGCAT_TABLE[cat]*2;
			} else if (sphinx > 2) {
				winSimbol = sphinx;
				winPerSymbol=FaraohGoldView.SPHINXTABLET_TABLE[sphinx]*2;
			} else if (tablet > 2) {
				winSimbol = tablet;
				winPerSymbol=FaraohGoldView.SPHINXTABLET_TABLE[tablet]*2;
			} else if (bird > 2) {
				winSimbol = bird;
				winPerSymbol=FaraohGoldView.BIRD_TABLE[bird]*2;
			} else {
				winSimbol = pharaoh;
				winPerSymbol=FaraohGoldView.PHARAOH_TABLE[pharaoh];
			}
		} else if (pharaoh == 3) {
			if (king > 4) {
				winSimbol = king;
				winPerSymbol=FaraohGoldView.KINGACE_TABLE[king]*2;
			} else if (ace > 4) {
				winSimbol = ace;
				winPerSymbol=FaraohGoldView.KINGACE_TABLE[ace]*2;
			} else if (bug > 4) {
				winSimbol = bug;
				winPerSymbol=FaraohGoldView.BUGCAT_TABLE[bug]*2;
			} else if (cat > 4) {
				winSimbol = cat;
				winPerSymbol=FaraohGoldView.BUGCAT_TABLE[cat]*2;
			} else if (sphinx > 3) {
				winSimbol = sphinx;
				winPerSymbol=FaraohGoldView.SPHINXTABLET_TABLE[sphinx]*2;
			} else if (tablet > 3) {
				winSimbol = tablet;
				winPerSymbol=FaraohGoldView.SPHINXTABLET_TABLE[tablet]*2;
			} else if (bird > 4) {
				winSimbol = bird;
				winPerSymbol=FaraohGoldView.BIRD_TABLE[bird]*2;
			} else {
				winSimbol = pharaoh;
				winPerSymbol=FaraohGoldView.PHARAOH_TABLE[pharaoh];
			}
		} else if (pharaoh == 4 || pharaoh == 5) {
			winSimbol = pharaoh;
			winPerSymbol=FaraohGoldView.PHARAOH_TABLE[pharaoh];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (cat > 2) {
			winSimbol = cat;
			winPerSymbol=FaraohGoldView.BUGCAT_TABLE[cat];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (bug > 2) {
			winSimbol = bug;
			winPerSymbol=FaraohGoldView.BUGCAT_TABLE[bug];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (tablet > 1) {
			winSimbol = tablet;
			winPerSymbol=FaraohGoldView.SPHINXTABLET_TABLE[tablet];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (sphinx > 1) {
			winSimbol = sphinx;
			winPerSymbol=FaraohGoldView.SPHINXTABLET_TABLE[sphinx];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (bird > 2) {
			winSimbol = bird;
			winPerSymbol=FaraohGoldView.BIRD_TABLE[bird];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (nine > 1) {
			winSimbol = nine;
			winPerSymbol=FaraohGoldView.NINE_TABLE[nine];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (queen > 2) {
			winSimbol = queen;
			winPerSymbol=FaraohGoldView.TENJACKQUEEN_TABLE[queen];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (king > 2) {
			winSimbol = king;
			winPerSymbol=FaraohGoldView.KINGACE_TABLE[king];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (ace > 2) {
			winSimbol = ace;
			winPerSymbol=FaraohGoldView.KINGACE_TABLE[ace];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (jack > 2) {
			winSimbol = jack;
			winPerSymbol=FaraohGoldView.TENJACKQUEEN_TABLE[jack];
			if(pharaoh>0) winPerSymbol*=2;
		} else if (ten > 2) {
			winSimbol = ten;
			winPerSymbol=FaraohGoldView.TENJACKQUEEN_TABLE[ten];
			if(pharaoh>0) winPerSymbol*=2;
		}
	}
}
